home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / include / appearance.h < prev    next >
C/C++ Source or Header  |  1993-09-15  |  13KB  |  389 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #ifndef APPEARANCEDEF
  13. #define APPEARANCEDEF
  14.  
  15. /*
  16.   #define AP_IDEBUG before #including this file to compile for
  17.   debugging
  18. */
  19.  
  20. #include "ooglutil.h"
  21. #include "vert.h"
  22. #include "3d.h"
  23. #include "color.h"
  24. #include "handle.h"
  25. #include <stdarg.h>
  26.  
  27. #define DONE 1
  28. #define ANOTHER 2
  29.  
  30. typedef struct LtLight {
  31.     struct LtLight *next;
  32.     Color ambient;
  33.     Color color;
  34.     Point position;        /* application-specified light position */
  35.     Point globalposition;    /* real light position; set & used only by mg */
  36.     float intensity;
  37.  
  38.     int Private;        /* private part; used only by mg */
  39.  
  40.     short location;        /* How to interpret the "position": */
  41. #define    LTF_GLOBAL    0x0        /* global coordinate system */
  42. #define    LTF_CAMERA    0x1        /* camera coordinates */
  43. #define    LTF_LOCAL    0x2        /* local coordinates
  44.                      * where appearance is attached. */
  45.  
  46.     short changed;
  47. } LtLight;
  48.  
  49.  
  50. typedef struct LmLighting {
  51.     REFERENCEFIELDS
  52.     int valid, override;     /* LMF_* inheritance bits */
  53.     Color ambient;
  54.     int    localviewer;
  55.     float attenconst, attenmult, attenmult2;
  56.     LtLight *lights;
  57.  
  58.     int Private;
  59.     int changed;
  60. } LmLighting;
  61.  
  62.  
  63. typedef struct Material {
  64.     REFERENCEFIELDS
  65.     int valid, override;    /* MTF_* inheritance bits */
  66.     Color emission;
  67.     Color ambient;
  68.     Color diffuse;
  69.     float alpha;
  70.     Color specular;
  71.     float shininess;
  72.     float ka, kd, ks;
  73.     Color edgecolor;        /* Color for polygon edges and other vectors */
  74.     Color normalcolor;        /* Color for surface-normal vectors */
  75.  
  76.     int Private;
  77.     int changed;
  78. } Material;
  79.  
  80. typedef struct Appearance {
  81.     REFERENCEFIELDS
  82.     Material    *mat, *backmat;        /* material properties */
  83.     LmLighting    *lighting;  /* attached lighting */
  84.     unsigned int flag;        /* APF_* shading,faces/edges,normals,transparency */
  85.     unsigned int valid;        /* APF_* bits control inheritance of these fields */
  86.     unsigned int override;  /* same APF_* flags: parent overrides child */
  87.     float nscale;        /* scale factor for drawing normals */
  88.     int linewidth;          /* how wide do lines appear (pixels) ? */
  89.     int shading;        /* APF_{CONSTANT,FLAT,SMOOTH} */
  90. }  Appearance;
  91.  
  92.  
  93.  
  94. /* the following tokens are used in LtSet and LtGet */
  95. #define LT_END        700
  96. #define    LT_AMBIENT    701    /* Color ambient */
  97. #define    LT_COLOR    702    /* Color color */
  98. #define    LT_POSITION    703    /* Point position */
  99. #define    LT_INTENSITY    704    /* double intensity */
  100. #define    LT_LOCATION    705    /* int location: LTF_{GLOBAL,CAMERA,LOCAL} */
  101.  
  102. #define LT_ABLOCK    706    /* void **ablock */
  103.  
  104.  
  105. /* the following tokens are used in LmSet and LmGet */
  106. #define LM_END          600    
  107. #define    LM_AMBIENT      601    /* Color ambient */
  108. #define    LM_LOCALVIEWER      602    /* int localviewer */
  109. #define    LM_ATTENC      603    /* double attenconst */
  110. #define    LM_ATTENM      604    /* double attenmult */
  111. #define    LM_ATTEN2      612    /* double attenmult2 */
  112. #define LM_LtSet      605    /* ... */
  113. #define LM_LIGHT      606    /* LtLight *light */
  114. #define LM_VALID      607    /* int mask (Get only) */
  115. #define LM_INVALID      608    /* int mask (unsets valid bits) */
  116. #define LM_OVERRIDE      609    /* int mask (sets override bits) */
  117. #define LM_NOOVERRIDE      610    /* int mask (unsets override bits) */
  118. #define LM_REPLACELIGHTS  611    /* int replace */
  119.  
  120. #define LM_ABLOCK      613    /* void **ablock */
  121.  
  122.  
  123. /* the following tokens are used in MtSet and MtGet */
  124. #define MT_END        500    
  125. #define MT_EMISSION    501    /* Color *emission */
  126. #define    MT_AMBIENT    502    /* Color *ambient */
  127. #define    MT_DIFFUSE    503    /* Color *diffuse */
  128. #define    MT_SPECULAR    504    /* Color *specular */
  129. #define    MT_Ka        505    /* double ka */
  130. #define    MT_Kd        506    /* double kd */
  131. #define    MT_Ks        507    /* double ks */
  132. #define    MT_ALPHA    508    /* double alpha */
  133. #define    MT_SHININESS    509    /* double shininess */
  134. #define    MT_EDGECOLOR    510    /* Color *edgecolor (for edges & vectors) */
  135. #define    MT_NORMALCOLOR    511    /* Color *normalcolor (for surface normals) */
  136. #define MT_VALID    512    /* int mask (Get only) */
  137. #define MT_INVALID    513    /* int mask (unsets valid bits) */
  138. #define MT_OVERRIDE    514    /* int mask (sets override bits) */
  139. #define MT_NOOVERRIDE    515    /* int mask (unsets override bits) */
  140.  
  141. #define MT_ABLOCK    516    /* void **ablock */
  142.  
  143.  
  144. /* the following tokens are used in ApSet and ApGet */
  145. #define AP_END        400    
  146. #define AP_DO        401    /* int mask (set flag bits) */
  147. #define AP_DONT     402    /* int mask (unset flag bits) */
  148. #define AP_MAT        403    /* Material *mat */
  149. #define AP_MtSet    404    /* ... */
  150. #define AP_LGT        405    /* LmLighting *lgt */
  151. #define AP_LmSet    406    /* ... */
  152. #define AP_NORMSCALE    407    /* float nscale */
  153. #define AP_LINEWIDTH    408    /* int linewidth */
  154. #define AP_VALID    409    /* int mask (Get only) */
  155. #define AP_INVALID    410    /* int mask (unsets valid bits) */
  156. #define AP_OVERRIDE    411    /* int mask (sets override bits) */
  157. #define AP_NOOVERRIDE    412    /* int mask (unsets override bits) */
  158. #define AP_SHADING    413    /* int shading (set to APF_{CONSTANT,FLAT,SMOOTH} */
  159. #define    AP_BACKMAT    414    /* Material *backmaterial */
  160.  
  161. #define AP_ABLOCK    415    /* void **ablock */
  162.  
  163.                 /* Flags to ApMerge, etc. */
  164. #define    APF_INPLACE     0x1    /* Merge in place */
  165. #define    APF_OVEROVERRIDE 0x2    /* src replaces dst even without src override */
  166.  
  167.  
  168. #ifndef AP_IDEBUG
  169. Appearance *    ApCreate( int attr, ... );
  170. Appearance *    ApSet( Appearance *ap, int attr, ... );
  171. #endif
  172. Appearance *    _ApSet(Appearance *ap, int attr1, register va_list *alist);
  173. int        ApGet( Appearance *ap, int attr, void *valuep );
  174. void        ApDelete( Appearance *ap );
  175. Appearance *    ApDefault( Appearance *ap );
  176. Appearance *    ApCopy( Appearance *from, Appearance *into );
  177. Appearance *    ApMerge( Appearance *src, Appearance *dst, int inplace );
  178. Appearance *    ApFLoad( Appearance *into, FILE *f, char *stream );
  179. Appearance *    ApLoad( Appearance *into, char *stream );
  180.  
  181.         /* Force 'override' bits on (for all valid fields)
  182.          * or off, in an Appearance.
  183.          */
  184. void     ApUseOverrides( Appearance *ap, int use_overrides );
  185.  
  186.         /* Erase fields in 'dst' corresponding to any in 'src';
  187.          * allows 'src' settings to propagate through 'dst',
  188.          * when 'dst' is its child.
  189.          */
  190. void    ApLetPropagate( Appearance *src, Appearance *dst );
  191.  
  192. #ifndef AP_IDEBUG
  193. Material *    MtCreate( int attr, ... );
  194. Material *    MtSet( Material *, int attr, ... );
  195. #endif
  196. int        MtGet( Material *, int attr, void *valuep );
  197.  
  198. void        MtDelete( Material * );
  199. Material *    MtDefault( Material * );
  200. Material *    MtLoad( Material *, char *filename );
  201. Material *    MtCopy( Material *from, Material *into );
  202. Material *    MtMerge( Material *src, Material *dst, int inplace );
  203. Material *    MtFLoad( Material *into, FILE *stream, char *filename );
  204. int        MtSave( Material *, char *filename );
  205. int        MtFSave( Material *mat, FILE *stream );
  206. void        MtPrint( Material * );
  207.  
  208.  
  209. #ifndef AP_IDEBUG
  210. LtLight *    LtCreate( int attr, ... );
  211. LtLight *    LtSet( LtLight *, int attr, ... );
  212. #endif
  213. int        LtGet( LtLight *, int attr, void *valuep );
  214. void         LtDelete( LtLight * );
  215. LtLight *    LtCopy( LtLight *, LtLight * );
  216. LtLight *    LtMerge( LtLight *, LtLight * );
  217. LtLight *    LtDefault( LtLight * );
  218. void         LtProperties( LtLight *, float, Color *, Point * );
  219. LtLight *         LtLoad( LtLight *, char *filename);
  220. LtLight *         LtFLoad( LtLight *, FILE *, char *filename);
  221. void         LtRemove( LmLighting *, LtLight * );
  222. void         LtAppend( LmLighting *, LtLight * );
  223. LtLight *    LtCopylist(LtLight *l, int mergeflag);
  224. void        LtDeletelist(LtLight *l);
  225.  
  226.  
  227. #ifndef AP_IDEBUG
  228. LmLighting *    LmCreate( int attr, ... );
  229. LmLighting *    LmSet( LmLighting *, int attr, ... );
  230. #endif
  231. int        LmGet( LmLighting *, int attr, void *valuep );
  232. void         LmDelete( LmLighting * );
  233. void         LmDelete( LmLighting * );
  234. void         LmDefault( LmLighting * );
  235. LmLighting *     LmLoad( LmLighting *, char *filename );
  236. LmLighting *    LmFLoad( LmLighting *, FILE *, char *filename );
  237. void         LmSave( LmLighting *, char *filename );
  238. int         LmFSave( LmLighting *, FILE *, char *filename );
  239. LmLighting *    LmMerge( LmLighting *src, LmLighting *dst, int inplace );
  240. LmLighting *    LmCopy( LmLighting *src, LmLighting *dst );
  241.  
  242. #define    LIGHTINGMAGIC    OOGLMagic('l', 1)
  243.  
  244. #define    LMF_LOCALVIEWER    0x1   /* Local viewer (flag valid) */
  245. #define    LMF_AMBIENT    0x2   /* Ambient light color */
  246. #define    LMF_ATTENC    0x4   /* attenuation constant factor */
  247. #define    LMF_ATTENM    0x8   /* attenuation linear factor */
  248. #define    LMF_ATTEN2    0x20  /* 1/r^2 attenuation factor */
  249. #define    LMF_REPLACELIGHTS    0x10  /* When merging, use only new lights, not union */
  250.  
  251. #define    MATMAGIC    OOGLMagic('m', 1)
  252.  
  253. #define MTF_EMISSION    0x1
  254. #define    MTF_AMBIENT    0x2
  255. #define    MTF_DIFFUSE    0x4
  256. #define    MTF_SPECULAR    0x8
  257. #define    MTF_Ka        0x10
  258. #define    MTF_Kd        0x20
  259. #define    MTF_Ks        0x40
  260. #define    MTF_ALPHA    0x80
  261. #define    MTF_SHININESS    0x100
  262. #define    MTF_EDGECOLOR    0x200
  263. #define    MTF_NORMALCOLOR    0x400
  264.  
  265.  
  266. #define    APMAGIC        OOGLMagic('a', 1)
  267.  
  268. /* The following bits are used in 'flag', 'valid', 'override' */
  269. #define    APF_FACEDRAW    0x2    /* Draw faces */
  270. #define    APF_EDGEDRAW    0x10    /* Draw edges */
  271. #define    APF_TRANSP    0x20    /* Enable transparency */
  272. #define    APF_EVERT    0x40    /* Evert surface normals */
  273. #define    APF_NORMALDRAW    0x80    /* Draw surface normals */
  274. #define    APF_VECTDRAW    0x100    /* Draw vectors/points */
  275.  
  276. /* The following bits are used in 'valid', 'override' */
  277. #define    APF_SHADING    0x1     /* Use 'shading' value */
  278. #define    APF_NORMSCALE    0x4    /* Use 'nscale' value to draw normals */
  279. #define    APF_LINEWIDTH    0x8    /* Use 'linewidth' value  */
  280.  
  281. /* Possible values for ap->shading field; these MUST be consecutive !!
  282.    (code outside the appearance library depends on this fact) */
  283. #define    APF_CONSTANT    0    /* constant-colored (unlighted) faces */
  284. #define APF_FLAT    1    /* Flat-shaded, lighted faces */
  285. #define    APF_SMOOTH    2    /* Gouraud-shaded faces, with lighting */
  286. #define    APF_CSMOOTH    3    /* Gouraud-shaded faces, without lighting */
  287.  
  288. #define    IS_SMOOTH(shading)  ((shading) >= APF_SMOOTH)
  289. #define    IS_SHADED(shading)  ((1<<(shading)) & ((1<<APF_FLAT)|(1<<APF_SMOOTH)))
  290.  
  291.  
  292. #ifdef AP_IDEBUG
  293.  
  294. Appearance *    ApCreate();
  295. Appearance *    ApSet();
  296. Material *    MtCreate();
  297. Material *    MtSet();
  298. LtLight *    LtCreate();
  299. LtLight *    LtSet();
  300. LmLighting *    LmCreate();
  301. LmLighting *    LmSet();
  302.  
  303. int lt_end = LT_END;
  304. int lt_ambient = LT_AMBIENT;
  305. int lt_color = LT_COLOR;
  306. int lt_position = LT_POSITION;
  307. int lt_intensity = LT_INTENSITY;
  308.  
  309. int lm_end = LM_END;
  310. int lm_ambient = LM_AMBIENT;
  311. int lm_localviewer = LM_LOCALVIEWER;
  312. int lm_attenc = LM_ATTENC;
  313. int lm_attenm = LM_ATTENM;
  314. int lm_ltset = LM_LtSet;
  315. int lm_light = LM_LIGHT;
  316. int lm_valid = LM_VALID;
  317. int lm_invalid = LM_INVALID;
  318. int lm_override = LM_OVERRIDE;
  319. int lm_nooverride = LM_NOOVERRIDE;
  320.  
  321. int mt_end = MT_END;
  322. int mt_emission = MT_EMISSION;
  323. int mt_ambient = MT_AMBIENT;
  324. int mt_diffuse = MT_DIFFUSE;
  325. int mt_specular = MT_SPECULAR;
  326. int mt_ka = MT_Ka;
  327. int mt_kd = MT_Kd;
  328. int mt_ks = MT_Ks;
  329. int mt_alpha = MT_ALPHA;
  330. int mt_shininess = MT_SHININESS;
  331. int mt_valid = MT_VALID;
  332. int mt_invalid = MT_INVALID;
  333. int mt_override = MT_OVERRIDE;
  334. int mt_nooverride = MT_NOOVERRIDE;
  335.  
  336. int ap_end = AP_END;
  337. int ap_do = AP_DO;
  338. int ap_dont = AP_DONT ; 
  339. int ap_mat = AP_MAT;
  340. int ap_mtset = AP_MtSet;
  341. int ap_lgt = AP_LGT;
  342. int ap_lmset = AP_LmSet;
  343. int ap_normscale = AP_NORMSCALE;
  344. int ap_linewidth = AP_LINEWIDTH;
  345. int ap_valid = AP_VALID;
  346. int ap_invalid = AP_INVALID;
  347. int ap_override = AP_OVERRIDE;
  348. int ap_nooverride = AP_NOOVERRIDE;
  349. int ap_shading = AP_SHADING;
  350.  
  351. int lmf_localviewer = LMF_LOCALVIEWER;
  352. int lmf_ambient = LMF_AMBIENT;
  353. int lmf_attenc = LMF_ATTENC;
  354. int lmf_attenm = LMF_ATTENM;
  355. int lmf_replacelights = LMF_REPLACELIGHTS;
  356.  
  357. int mtf_emission = MTF_EMISSION;
  358. int mtf_ambient = MTF_AMBIENT;
  359. int mtf_diffuse = MTF_DIFFUSE;
  360. int mtf_specular = MTF_SPECULAR;
  361. int mtf_ka = MTF_Ka;
  362. int mtf_kd = MTF_Kd;
  363. int mtf_ks = MTF_Ks;
  364. int mtf_alpha = MTF_ALPHA;
  365. int mtf_shininess = MTF_SHININESS;
  366.  
  367. int apf_facedraw = APF_FACEDRAW;
  368. int apf_edgedraw = APF_EDGEDRAW;
  369. int apf_transp = APF_TRANSP;
  370. int apf_evert = APF_EVERT;
  371.  
  372. int apf_shading = APF_SHADING;
  373. int apf_normscale = APF_NORMSCALE;
  374. int apf_linewidth = APF_LINEWIDTH;
  375.  
  376. int apf_constant = APF_CONSTANT;
  377. int apf_flat = APF_FLAT;
  378. int apf_smooth = APF_SMOOTH;
  379.  
  380. #endif /* AP_IDEBUG */
  381.  
  382. void ApFSave( Appearance *ap, Handle *aphandle, FILE *f, char *fname );
  383. int ApStreamIn(Pool *p, Handle **hp, Appearance **app);
  384. int ApStreamOut(Pool *p, Handle *h, Appearance *ap);
  385.  
  386. #endif /* APPEARANCEDEF */
  387.  
  388.  
  389.